import request from "../../utils/request";
import axios, { AxiosRequestConfig } from 'axios';

import type { OrderListData, OrderDetailsData } from "./type";

enum API {
  // 获取订单列表
  GET_ORDER_LIST_URL = "/artificial/cashier/index/list",

  // 获取商品详情
  GET_ORDER_DETAILS_URL = "/artificial/cashier/index/details/ids/",

  // 拉起支付
  PULL_PAY_URL = "/artificial/cashier/index/pay",

  // 获取订单状态
  GET_ORDER_STATUS = "/artificial/cashier/index/find",
}

export const reqGetOrderList = (data: any) => request.post<any, OrderListData>(API.GET_ORDER_LIST_URL, data);

export const reqGetOrderDetails = (id: string | number, data: any) => request.post<any, OrderDetailsData>(API.GET_ORDER_DETAILS_URL + id, data);

export const reqPullPay = (data: any, signal?: AbortSignal) => {
  const config: AxiosRequestConfig = {
    method: 'post',
    url: API.PULL_PAY_URL,
    data: data,
    signal: signal // 添加 AbortSignal
  };

  return request(config);
};

export const reqOrderStatus = (data: any) => request.post<any, any>(API.GET_ORDER_STATUS, data);
